package com.carbohydrate42.kotlin_compose_demo.compose

import android.content.Context
import android.hardware.ConsumerIrManager
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import com.carbohydrate42.kotlin_compose_demo.util.DebugUtil

/**
 * 参考 (手上暂时没有有红外功能的手机, 放弃了, 如果要用 3.5mm 耳机孔当红外, 需要额外整外设, 方法也不一样)
 *
 * https://www.jianshu.com/p/f7ea77f2aa3e
 */
@Composable
@Preview(showSystemUi = true, showBackground = true)
fun TryIrSensor() {
    val context = LocalContext.current
    val consumerIrManager =
        context.getSystemService(Context.CONSUMER_IR_SERVICE) as ConsumerIrManager

    LaunchedEffect(Unit) {
        consumerIrManager.let {
            DebugUtil.debugLog(consumerIrManager.hasIrEmitter().toString())
            DebugUtil.toast(consumerIrManager.hasIrEmitter().toString())
        }
    }
}